#include "StdAfx.h"
#include "TdUtils.h"

namespace TPT = TdParallelTransportApi;

char * TPT::GetLogLevelString(TPT::TdLogLevel level)
{
	switch(level)
	{
	case TPT::TdLogLevel::Off:
		return "Off";
	case TPT::TdLogLevel::Low:
		return "Low";
	case TPT::TdLogLevel::Medium:
		return "Medium";
	case TPT::TdLogLevel::High:
		return "High";
	default:
		return 0;
	}
}

System::String^ TPT::GetToken(System::String^ definition, int* off)
{
	System::String^ token;
	int start = *off;
	bool quotedId = (definition[start] == '[');
	if (quotedId)
	{
		*off = definition->IndexOf(']', start);
		if (*off < 0)
		{
			throw gcnew System::ArgumentException("Invalid Column Definition.", "definition");
		}

		token = definition->Substring(start + 1, *off - start - 1);
		*off++;
	}
	else
	{
		*off = definition->IndexOfAny(gcnew array<wchar_t> { ' ', '\t', '(' }, start);
		if (*off < 0)
		{
			token = definition->Substring(start);
		}
		else
		{
			token = definition->Substring(start, *off - start);
		}
	}

	return token;
}